<template>
	<view class="waitForTeacher">
		<template>
			<input type="text" placeholder="请输入学生账号" v-model="studentUser">
			<input type="text" placeholder="请输入学生密码" v-model="studentPwd">
			<button type="default" @click="studentLogin">登录</button>
			
			<button type="default" @click="seejj">观看讲解</button>
		</template>
	</view>
</template>

<script>
	export default {
		name: 'waitForTeacher',
		data() {
			return {
				studentUser: '',
				studentPwd: '',
				userInfo: {}
			};
		},
		onLoad() {
			// uni.navigateTo({
			// 	url: `/pages/index/canvasLive?ip=47.104.203.80`
			// })
		},
		methods: {
			seejj(){
				uni.navigateTo({
					url: '/pages/seeLive'
				})
			},
			studentLogin(){
				this.$HT({
					url: '/yUser/YLogin',
					data: {
						mobile: this.studentUser,
						password: this.studentPwd,
					},
					isPost: true
				}).then( res => {
					console.log(res)
					this.userInfo = res.data.user
					uni.showLoading({
						title: '等待讲师发送邀请'
					})
					this.getPlayUrl()
					setStorage('token', res.data.token)
				})
			},
			getPlayUrl(){
				this.$HT({
					url: '/yLiveStudent/findMachineByStudentId?studentId=' + this.userInfo.ID,
				}).then( res => {
					console.log(res,'findMachineByStudentIdfindMachineByStudentIdfindMachineByStudentId')
					if(res.data.machineIp){
						uni.hideLoading()
						uni.showToast({
							title:'正在进入',
							icon: 'none'
						})
						let url = res.data.typeValue == 1 ? '/pages/index/livePage?ip=' : '/pages/index/canvasLive?ip='
						setTimeout(() => {
							uni.navigateTo({
								url: url + res.data.machineIp
							})
						}, 1000)
						return
					}
					setTimeout(() => {
						this.getPlayUrl()
					}, 2000)
				}).catch(err => console.log(err,'==='))
			}
		}
	};
</script>

<style lang="scss">
	input, button{
		width: 90%;
		height: 100rpx;
		border: 1rpx solid #CCCCCC;
		margin: auto;
		margin-top: 30rpx;
		border-radius: 20rpx;
		padding-left: 20rpx;
		padding-right: 20rpx;
	}
	button{
		border: none;
	}
</style>
